package com.xz.simplerpc.console;

import com.google.common.base.Optional;
import com.xz.simplerpc.console.domain.Config;
import com.xz.simplerpc.console.rest.SimpleRpcRest;
import com.xz.simplerpc.console.server.RestfulServer;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;


/**
 * Created by fingal on 2018/1/14.
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
public final class ConsoleBootstrap {

    private static final String CONSOLE_PATH = "console";

    /**
     * 启动RESTful服务并加载页面.
     *
     * @param args 启动参数
     * @throws Exception 启动服务器异常
     */
    //CHECKSTYLE:OFF
    public static void main(final String[] args) throws Exception {
        //CHECKSTYLE:ON
        int port = 8899;
        if (1 == args.length) {
            try {
                port = Integer.parseInt(args[0]);
            } catch (final NumberFormatException ex) {
                log.warn("Wrong port format, using default port 8899 instead.");
            }
        }
        RestfulServer restfulServer = new RestfulServer(port);
        restfulServer.start(SimpleRpcRest.class.getPackage().getName(), Optional.of(CONSOLE_PATH));
        Config.load();
    }
}

